package com.huangpeng.sdst.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huangpeng.sdst.entity.Order;
import com.huangpeng.sdst.entity.OrderQueryBo;
import com.huangpeng.sdst.entity.SearchBo;
import com.huangpeng.sdst.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author huangpeng
 * @Title 订单控制类
 * @Package
 * @Date 2020/8/25 16:16
 * @Description
 * @Version 1.0
 */
@RequestMapping("/order/")
@RestController
public class OrderController {
    @Autowired
    private IOrderService orderService;

    /**
     * 新增订单
     * @param order
     * @return
     */
    @PostMapping("saveOrder")
    public boolean saveOrder(@RequestBody Order order){
        boolean flag = orderService.saveOrder(order);
        return flag;
    }

    /**
     * 更新订单
     * @param order
     * @return
     */
    @PostMapping("updateOrder")
    public boolean updateOrder(@RequestBody Order order){
        boolean flag = orderService.updateOrder(order);
        return flag;
    }

    /**
     * 订单分页查询
     * @param queryBo
     * @return
     */
    @PostMapping("getOrderPageList")
    public IPage<Order> getOrderPageList(@RequestBody SearchBo<OrderQueryBo> queryBo){
        IPage<Order> modelList = orderService.getOrderPageList(queryBo);
        return modelList;
    }

    /**
     * 订单集合查询
     * @param queryBo
     * @return
     */
    @PostMapping("getOrderList")
    public List<Order> getOrderList(@RequestBody SearchBo<OrderQueryBo> queryBo){
        List<Order> modelList = orderService.getOrderList(queryBo);
        return modelList;
    }

    /**
     * 订单查询根据id
     * @param orderId
     * @return
     */
    @PostMapping("getOrderById")
    public Order getOrderById(Long orderId){
        Order model = orderService.getOrderById(orderId);
        return model;
    }

    /**
     * 删除订单
     * @param orderId
     * @return
     */
    @PostMapping("deleteOrder")
    public Integer deleteOrder(Long orderId){
        Integer num = orderService.deleteOrder(orderId);
        return num;
    }
}
